package com.theorydance.content_search.util;

import java.util.List;

/**
 * 条件组
 */
public class GroupCondition implements Condition{
	
	private List<Condition> conditionList;
	private Join join;
	
	public GroupCondition(List<Condition> conditionList, Join join) {
		this.conditionList = conditionList;
		this.join = join;
	}
	
	@Override
	public boolean apply() {
		if (join.equals(Join.AND)) {
			// 使用AND方式，只要有一个为false，结果就是false
			return conditionList.stream().allMatch(item -> item.apply());
		} else { // join.equals(Join.OR)
			// 使用OR方式，只要有一个为true，结果就是true
			return conditionList.stream().anyMatch(item -> item.apply());
		}
	}
}
